package com.nbgroup.web;

import com.nbgroup.dao.UserDao;
import com.nbgroup.entity.Appraise;
import com.nbgroup.entity.Menu;
import com.nbgroup.entity.User;
import com.nbgroup.service.Appraise.AppraiseService;
import com.nbgroup.service.MenuService;
import com.nbgroup.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.security.Principal;
import java.util.List;
import java.util.Map;

/**
 * Created by 隔壁老王 on 2018/6/19.
 */
@Controller
public class MainController {

    @Autowired
    private UserDao userDao;
    @Autowired
    AppraiseService appraiseService;
    @Autowired
    MenuService menuService;
    @Autowired
    RoleService roleService;
    @RequestMapping("/")
    public String root() {
        return "redirect:/index";
    }

    @RequestMapping("/index")
    public String index(Map<String, Object> map ,Principal principal) {
        System.out.println(principal.getName());
        User user = userDao.findByUsernameAndSts(principal.getName(), "1");
        map.put("user", user);
        List<Menu> menu = menuService.getMenuByRoleId(user.getId()+"");
        map.put("menu", menu);
        return "index";
    }

    //测试跳转demo
    @RequestMapping("/push")
    public String push() {
        return "push";
    }
    @RequestMapping("/detail")
    public String detail() {
        return "detail";
    }
    @RequestMapping("/floor")
    public String floor() {
        return "/floor/floor_show";
    }


    @RequestMapping("/screen")
    public String screen(Map<String, Object> map) {
//        List<Appraise> appraiseList = appraiseService.getAppraiseForScreenNew();
//        map.put("appraiseList", appraiseList);
        return "screen/screen";
    }
    /*
     *   评价管理页面
     * @author 王玉涛
     * @Date 2018/8/27 16:22
     * @param
     * @return
     */
    @RequestMapping("/appraise")
    public String appraise(Map<String,Object>map,Integer lid) {
        map.put("appraise",appraiseService.getAppraises(0,lid));
        return "/appraise/appraise";
    }
    @RequestMapping("/user/index")
    public String userIndex(Map<String, Object> map,User user) {
        map.put("user", user);
        return "/user/index";
    }

    @RequestMapping("/login")
    public String login() {
        return "signin";
    }

    @RequestMapping("/login-error")
    public String loginError(Map<String, Object> map) {
        map.put("loginError", true);
        return "signin";
    }

    @GetMapping("/401")
    public String accesssDenied() {
        return "401";
    }

    @GetMapping("/test")
    public String test() {
        return "test";
    }

    @RequestMapping("/toControl")
    public String toControl(String onLoadUrl, Map<String, Object> map) {
        System.out.println("onLoadUrl=" + onLoadUrl);
        map.put("onLoadUrl", onLoadUrl);
        return "control_platform";
    }
    @RequestMapping("/ToThirdIndex")//http://localhost:28080/ToThirdIndex?username=admin&password=123456
    public String ToThirdIndex(Map<String, Object> map,String username,String password ) {
        System.out.println(username+"_______ "+password);
        User user = userDao.findByUsernameAndSts(username, "1");
        map.put("user", user);
        return "index";
    }
}
